package com.zksw.core;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 辅助分页类 <br>
 *
 */
@Data
@NoArgsConstructor
public class PageInfo {
    public static final String SORT_TYPE_ASC = "asc";
    public static final String SORT_TYPE_DES = "desc";
    private long totals;
    private int startIndex;
    private int pageSize = 12;
    private String sortItem;
    private String sortType = SORT_TYPE_DES;

    /**
     * @param startIndex
     * @param pageSize
     */
    public PageInfo(final int startIndex, final int pageSize) {
        this(startIndex, pageSize, "", SORT_TYPE_ASC);
    }

    /**
     * @param startIndex
     * @param pageSize
     * @param sortItem
     */
    public PageInfo(final int startIndex, final int pageSize, final String sortItem) {
        this(startIndex, pageSize, sortItem, SORT_TYPE_ASC);
    }

    /**
     * @param startIndex
     * @param pageSize
     * @param sortItem
     * @param sortType   (asc|desc)
     */
    public PageInfo(final int startIndex, final int pageSize, final String sortItem, final String sortType) {
        this.startIndex = startIndex;
        this.pageSize = pageSize;
        this.sortItem = sortItem;
        this.sortType = sortType;
    }

    public int getTotalPage() {
        int ret = (int)totals/pageSize;
        int mod = (int)totals % pageSize;
        if (mod != 0) {
            ret = ret +1;
        }
        if (ret == 0) ret = 1;
        return ret;
    }
}
